<template>
    <div class="base-menu-boxfixed base-menu-fixed">
        <div class="base-menu-box">
            <div class="base-menu-box-menu">
                <a-menu :inline-collapsed="collapsed" v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys"
                    style="width: 100%;height: 100%;" mode="inline" @click="handleClick">
                    <nav v-for="fmenu, mkey in basicRoutes">
                        <template v-if="fmenu.children && fmenu.children.length > 0">
                            <a-menu-item-group :key="fmenu.path">
                                <template #title>
                                    <div class="base-menu-title">{{ fmenu.meta.title }}</div>
                                </template>
                                <a-menu-item :key="v.path" v-for="v in fmenu.children" @click="handleClickMenuItem(v)">{{
                                    v.meta?.title
                                }}</a-menu-item>
                            </a-menu-item-group>
                        </template>
                        <template v-else>
                            <a-menu-item-group :key="fmenu.path">
                                <a-menu-item :key="fmenu.path" @click="handleClickMenuItem(fmenu)">{{
                                    fmenu.meta?.title
                                }}</a-menu-item>
                            </a-menu-item-group>
                        </template>
                    </nav>
                </a-menu>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
import { MenuUnfoldOutlined, MenuFoldOutlined } from '@ant-design/icons-vue';
import type { RouteRecordRaw, RouteRecordName } from 'vue-router';
import { useRouter, useRoute } from 'vue-router';
import { basicRoutes } from '@/router/menu';
import { ref, watch, onMounted, nextTick } from 'vue';
import type { MenuProps } from 'ant-design-vue';
const selectedKeys = ref<RouteRecordName[]>(['/home']);
const openKeys = ref<string[] | number[]>([1]);
const router = useRouter();
const route = useRoute();
let collapsed = ref(false);
const handleClick: MenuProps['onClick'] = e => {
    // console.log('click', e);
};
const handleClickMenuItem = (item: RouteRecordRaw) => {
    router.push({
        path: item.path
    })
}
watch(() => route.path, () => {
    selectedKeys.value = [route.path];
})
</script>

<style lang="less" scoped>
.base-menu-title {
    margin-top: 16px;
    margin-bottom: 16px;
    font-size: 13px;
}

.base-menu-title:after {
    position: relative;
    top: 12px;
    display: block;
    width: calc(100% - 20px);
    height: 1px;
    background: #f0f0f0;
    content: "";
}

.base-menu-boxfixed {
    width: 256px;
    height: 100vh;
}

.base-menu-fixed {
    .base-menu-box {
        position: fixed;
        display: flex;
        height: 100vh;
        flex-direction: column;

        .base-menu-box-menu {
            overflow: auto;
            flex: 1;
        }
    }
}

.base-menu-box-toggle {
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    padding: 10px;
}

.base-menu-box {
    height: 100%;
    width: 256px;
    box-sizing: border-box;
    left: 0px;
    top: 0px;
}
</style>

<style>
.base-menu-box-menu::-webkit-scrollbar {
    width: 2px;
    height: 0px;
    background-color: #eee;
}

.base-menu-box-menu::-webkit-scrollbar-track {
    border-radius: 10px;
}

/* 滚动条滑块 */
.base-menu-box-menu::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: #1890ff;
}
</style>

